#include<bits/stdc++.h>
using namespace std;

const int inf = 0x3f3f3f3f;
int dist[5015];
int a[5015][5015];
bool vis[5015];
int n, m;

int prim()
{
	int ans = 0;
	dist[1] = 0;
	for(int i = 1;i <= n;i++)
	{
		int next = -1;
		for(int j = 1;j <= n;j++)
		{
			if(!vis[j] && (next == -1 || dist[next] > dist[j]))
			{
				next = j;
			}
		}
//		cout<<next<<" "<<ans<<endl;
		if(next == -1 || dist[next] == inf)
			return inf;
//		cout<<dist[next]<<endl;
		ans += dist[next];
		vis[next] = 1;
		for(int j = 1;j <= n;j++)
		{
			dist[j] = min(dist[j], a[next][j]);
//			cout<<j<<" "<<dist[j]<<endl;
		}	
	}
	return ans;
}

signed main()
{
	cin>>n>>m;
	memset(vis, 0, sizeof vis);
//	memset(a, 0x3f, sizeof a);
//	memset(dist, 0x3f, sizeof dist);
	for(int i = 1;i <= n;i++)
	{
		for(int j = 1;j <= n;j++)
			a[i][j] = inf;
		dist[i] = inf;
	}
	int x, y, t;
	for(int i = 1;i <= m;i++)
	{
		cin>>x>>y>>t;
		a[x][y] = a[y][x] = min(a[x][y], t);
//		cout<<x<<" "<<y<<" "<<a[x][y]<<endl;
	}
	int ans = prim();
	int cnt = accumulate(vis+1, vis+n+1, 0);
//	cout<<cnt<<endl;
	if(accumulate(vis+1, vis+n+1, 0) == n)
		cout<<ans<<endl;
	else
		cout<<"orz"<<endl;
//	if(ans != inf)
//		cout<<ans<<endl;
//	else
//		cout<<"orz"<<endl;
	return 0;
}

